<?php
namespace app\admin\controller;

use app\common\model\ShouyeReserve as ShouyeReserveModel;
use app\common\controller\AdminBase;
use think\Db;
use think\Session;
/**
 * 导航管理
 * Class Nav
 * @package app\admin\controller
 */
class Reserve extends AdminBase
{
	protected $nav_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->reserve_model  = new ShouyeReserveModel();
    }

     /**
     * 预留信息列表
     * @return mixed
     */
    public function index($keyword = '',$page = 1)
    {
    	$reservelist = $this->reserve_model->getReserveList($keyword,$page);
        return $this->fetch('index',['keyword'=>$keyword,'reservelist'=>$reservelist]);
    }


    /**
     * 删除留言
     * @param int   $id
     * @param array $ids
     */
    public function delete($id = 0,$ids = [])
    {
        $id = $ids ? array_merge($ids) : $id;
        if($id){
            if($this->reserve_model->destroy($id)){
                return $this->success('删除成功');
            }else{
                return $this->error('删除失败');
            }
        }else{
            return $this->error('请选择需要删除的内容');
        }
    }

    /**
     * 查看并处理页面
     * @param int   $id
     * @param array $ids
     */
    public function reading($id)
    {
        $reserveInfo = $this->reserve_model->getReserveInfo($id);
        return  $this->fetch('reading',['reserveInfo'=>$reserveInfo]);
    }

    /**
     * 更新预留信息状态
     * @param int   $id
     * @param array $ids
     */
    public function update($id)
    {
        $reserved = $this->reserve_model->find($id);
        $reserved->status        = '1';
        $reserved->publish_time  = date('Y-m-d H:i:s',time());
        $reserved->contactperson = Session::get('admin_name');
        if($reserved->save()){
            return $this->success('更新成功');
        }else{
            return $this->error('更新失败');
        }
    }

}